package cn.pconline.autoclub.util.ubb.node;

import cn.pconline.autoclub.util.ubb.EscapeUtils;
import cn.pconline.autoclub.util.ubb.Node;

/**
 *
 * @author xiawen
 */
public class MediaNode extends AbstractNode {

    public MediaNode() {
    }

    private MediaNode(String name, String attribute) {
        super.name = name;
        super.attribute = attribute;
    }

    @Override
    public StringBuilder getText(java.util.LinkedList<Node> stack) {
        StringBuilder sb = new StringBuilder();
        String width = "500";
        String height = "375";

        if (attribute != null) {
            String[] wh = attribute.split("[x|\\,]");
            if (wh.length == 2) {
                width = wh[0];
                height = wh[1];
            }
        }
        //default
//		sb.append("<object width=\"").append(width).append("\" height=\"").append(height).append("\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" align=\"center\" border=\"0\">");
//		sb.append("<param name=\"AutoStart\" value=\"0\"><param name=\"Balance\" value=\"0\"><param name=\"enabled\" value=\"-1\"><param name=\"EnableContextMenu\" value=\"-1\"><param name=\"url\" value=\"").append(text).append("\"><param name=\"PlayCount\" value=\"3\"><param name=\"rate\" value=\"1\"><param name=\"invokeURLs\" value=\"0\"><param name=\"baseURL\" value=\"\"><param name=\"stretchToFit\" value=\"0\"><param name=\"volume\" value=\"80\"><param name=\"mute\" value=\"0\"><param name=\"uiMode\" value=\"full\"><param name=\"windowlessVideo\" value=\"0\"><param name=\"fullScreen\" value=\"0\"><param name=\"enableErrorDialogs\" value=\"-1\">");
//		sb.append("</object>");

        //youku.com 56.com
        sb.append("<embed width=\"").append(width).append("\" height=\"").append(height).append("\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" wmode=\"transparent\" bgcolor=\"#ffffff\" quality=\"high\" src=\"").append(text).append("/.swf\" allowscriptaccess=\"never\" allownetworking=\"internal\">");
       
        //sina
        //sb.append("<div><object id=\"ssss\" width=\"480\" height=\"370\" ><param name=\"allowScriptAccess\" value=\"always\" /><embed pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=40820202_1270492934/s.swf\" type=\"application/x-shockwave-flash\" name=\"ssss\" allowFullScreen=\"true\" allowScriptAccess=\"always\" width=\"480\" height=\"370\"></embed></object></div>");

        //56.com
       
        return sb;
    }

    @Override
    public void appendText(CharSequence text) {
        EscapeUtils.appendAttribute(text, super.text);
    }

    @Override
    public Node copyWithoutText() {
        return new MediaNode(name, attribute);
    }

    @Override
    public Node build(String name, String attribute) {
        return new MediaNode(name, attribute);
    }
}
